package com.zjbti.jsb;

import android.annotation.SuppressLint;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class DBUtils {
    private static DBUtils instance=null;
    private static SQLiteHelper helper;
    private static SQLiteDatabase db;
    public DBUtils(Context context){
        helper=new SQLiteHelper(context);
        db = helper.getWritableDatabase();
    }
    public static DBUtils getInstance(Context context){
        if ((instance==null)){
            instance=new DBUtils(context);
        }
        return instance;
    }
    @SuppressLint("Range")
    public List<NoteBean> queryNote(){
        List<NoteBean> list=new ArrayList<NoteBean>();
        String sql="SELECT * FROM " + SQLiteHelper.U_NOTEPAD + " ORDER BY id DESC";
        Cursor cursor = db.rawQuery(sql,null);
        if(cursor!=null){
            while (cursor.moveToNext()){
                NoteBean bean = new NoteBean();
                int id=cursor.getInt(cursor.getColumnIndex("id"));
                String title = cursor.getString(cursor.getColumnIndex("title"));
                String content = cursor.getString(cursor.getColumnIndex("content"));
                String time = cursor.getString(cursor.getColumnIndex("time"));
                bean.setId(id);
                bean.setTitle(title);
                bean.setContent(content);
                bean.setTime(time);
                list.add(bean);
            }
            cursor.close();
        }
        return list;
    }
//    public static final String getTime(){
//        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日 HH：妈妈：ss");
//        Date date=new Date(System.currentTimeMillis());
//        return simpleDateFormat.format(date);
//    }
//    public boolean saveNote(String title,String content,String time){
//        boolean saveSuccess=false;
//
//    }
}
